import type { User } from '@/common/types/user-type'
import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useUserStore = defineStore(
  'user',
  () => {
    const userInfo = ref<User | null>()

    // 设置用户信息
    const setUserInfo = (val: User) => {
      userInfo.value = { ...userInfo.value, ...val }
    }

    // 清空用户信息
    const clearUserInfo = () => {
      userInfo.value = null
    }
    return {
      userInfo,
      setUserInfo,
      clearUserInfo,
    }
  },
  {
    persist: true,
  },
)
